package cn.edu.scau.cmi.guihao.pane;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.guihao.abstractFactory.InsuranceFactory;
import cn.edu.scau.cmi.guihao.interProgramming.abstractFactory.Insurance;
import cn.edu.scau.cmi.guihao.interProgramming.abstractFactory.InsuranceCompany;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;

public class AbstractFactoryPnae extends Pane implements Initializable{

	@FXML
	private Text name;
	
	@FXML
	private ComboBox<String> selectInsuranceType;
	
	@FXML
	private TextArea displayMessage;
	
	@FXML
	private ImageView photoView;
	
	@FXML
	private ComboBox<String> selectCompany;
	
	public AbstractFactoryPnae() {
		loadFXML();
	}
	
	public void loadFXML() {
		FXMLLoader loader = new FXMLLoader(getClass().getResource("/cn/edu/scau/cmi/guihao/view/AbstractFactoryView.fxml"));
        loader.setRoot(this);
        loader.setController(this);
        try {
            loader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	//该方法在构造方法执行完毕后执行
    @Override
    public void initialize(URL location, ResourceBundle resources) {
		ObservableList<String> insuranceType = FXCollections.observableArrayList("身体受伤","汽车损坏");
		ObservableList<String> companyType = FXCollections.observableArrayList("PICC","PingAn");
		selectInsuranceType.setItems(insuranceType);
		selectCompany.setItems(companyType);
		Image image = new Image("/cn/edu/scau/cmi/guihao/img/timg.jpg");
		photoView.setImage(image);
    }
	
	public void Init() {
		ObservableList<String> insuranceType = FXCollections.observableArrayList("身体受伤","汽车损坏");
		ObservableList<String> companyType = FXCollections.observableArrayList("PICC","PingAn");
		selectInsuranceType.setItems(insuranceType);
		selectCompany.setItems(companyType);
		Image image = new Image("/cn/edu/scau/cmi/guihao/img/timg.jpg");
		photoView.setImage(image);
	}
	
	@FXML
	public void onBtnClick() {
		System.out.println(selectCompany.getValue()+" "+selectInsuranceType.getValue()+"   "+name.getText());
		InsuranceCompany insuranceCompany = InsuranceFactory.createInsuranceOnFactory(selectCompany.getValue());
		Insurance insurance = insuranceCompany.createInsurance(selectInsuranceType.getValue(), name.getText());
		displayMessage.setText(insurance.getInsuranceOrder());
	}

	
	
}
